package cn.tedu.datamanager.mapper;


import cn.tedu.datamanager.pojo.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductMapper {

    @Insert("insert into product(title,url,price,old_price,sale_count,num,day,server_id) values(#{title},#{url},#{price},#{old_price},#{sale_count},#{num},#{day},#{server_id})")
    void insert(Product product);

    @Select("select id,title,price,old_price,sale_count,url,day,overdue,server_id from product")
    List<Product> select();

    @Select("select id,title,price,old_price,sale_count,url,day,overdue from product where overdue != '已过期'")
    List<Product> selectNotOverDue();

    @Delete("delete from product where id=#{id}")
    void deleteById(int id);

    @Select("select url from product where id=#{id}")
    String selectUrlById(int id);

    @Select("select id,title,price,old_price,sale_count,url from product")
    List<Product> selectIndex();

    @Select("select id,title,price,num,old_price,sale_count,url,day,overdue,server_id from product where id=#{id}")
    Product selectById(int id);

    /**
     * 查询数据库中所有的serverId,用于添加商品时展示
     * @return serverId集合
     */
    List<Integer> selectServerId();

    @Update("update product set title=#{title},price=#{price},sale_count=#{sale_count},old_price=#{old_price},num=#{num},day=#{day},url=#{url},server_id=#{server_id} where id=#{id}")
    void update(Product product);

    @Update("update product set overdue='已过期' where id=#{id}")
    void updateOverdue1(Integer id);

    @Update("update product set overdue='48小时内过期' where id=#{id}")
    void updateOverdue2(Integer id);

    @Update("update product set overdue='72小时内过期' where id=#{id}")
    void updateOverdue3(Integer id);

    @Update("update product set overdue='正常销售' where id=#{id}")
    void updateOverdue4(Integer id);
}

